﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using DemoQLKhoSX.Library;

namespace DemoQLKhoSX.DatabaseAccessLayer
{
    public class XuatDAO
    {
        private DBConnection conn;

        public XuatDAO()
        {
            conn = new DBConnection();
        }

        public DataTable searchByID(string id)
        {
            string query = string.Format("select * from TBL_Xuat where IDXuat = @id");
            SqlParameter[] sqlParameters = new SqlParameter[1];
            sqlParameters[0] = new SqlParameter("@id", SqlDbType.VarChar);
            sqlParameters[0].Value = Convert.ToString(id);
            return conn.executeSelectQuery(query, sqlParameters);
        }

        public bool addXuat(string idxuat, string idkhach, string idthukho, string idhang, DateTime ngayxuat, int soluongxuat)
        {
            string query = string.Format("insert into TBL_Xuat values(@idxuat,@idkhach,@idthukho,@idhang,@ngayxuat,@soluongxuat)");
            SqlParameter[] sqlParameters = new SqlParameter[6];
            sqlParameters[0] = new SqlParameter("@idxuat", SqlDbType.VarChar);
            sqlParameters[0].Value = Convert.ToString(idxuat);
            sqlParameters[1] = new SqlParameter("@idkhach", SqlDbType.VarChar);
            sqlParameters[1].Value = Convert.ToString(idkhach);
            sqlParameters[2] = new SqlParameter("@idthukho", SqlDbType.VarChar);
            sqlParameters[2].Value = Convert.ToString(idthukho);
            sqlParameters[3] = new SqlParameter("@idhang", SqlDbType.VarChar);
            sqlParameters[3].Value = Convert.ToString(idhang);
            sqlParameters[4] = new SqlParameter("@ngayxuat", SqlDbType.DateTime);
            sqlParameters[4].Value = Convert.ToString(ngayxuat);
            sqlParameters[5] = new SqlParameter("@soluongxuat", SqlDbType.Int);
            sqlParameters[5].Value = Convert.ToString(soluongxuat);
            return conn.executeInsertQuery(query, sqlParameters);
        }
    }
}
